package com.knight.concurrent.chapter11;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 主题
 * @author: knight
 * @Date: 2019-03-11 19:53
 */
public class Subject {

    private List<ObServer> obServers = new ArrayList<>();

    private int state;

    public void setState(int state) {
        if (this.state == state) {
            return;
        }
        this.state = state;
        notifyAllObServer();
    }

    public int getState() {
        return state;
    }

    public void attach(ObServer obServer) {
        obServers.add(obServer);
    }

    private void notifyAllObServer() {
        obServers.stream().forEach(ObServer::update);
    }


}
